<?php
/* Author: tbloc@cantho.gov.vn */
class Chi{  
//Properties
private $CHI_ID;
private $CHI_SO_PHIEU;
private $CHI_NGUOI_NHAN;
private $CHI_NOI_DUNG;
private $CHI_SO_TIEN;
private $CHI_DIA_CHI;
private $CHI_PHAN_LOAI;
private $CHI_NGAY_CHI;
private $IS_ACTIVE;
//properties set get 
public function setCHI_ID($CHI_ID) 
{
	$this->CHI_ID = $CHI_ID;
}
public function getCHI_ID()
{
	return $this->CHI_ID;
}	        
public function setCHI_SO_PHIEU($CHI_SO_PHIEU) 
{
	$this->CHI_SO_PHIEU = $CHI_SO_PHIEU;
}
public function getCHI_SO_PHIEU()
{
	return $this->CHI_SO_PHIEU;
}	        
public function setCHI_NGUOI_NHAN($CHI_NGUOI_NHAN) 
{
	$this->CHI_NGUOI_NHAN = $CHI_NGUOI_NHAN;
}
public function getCHI_NGUOI_NHAN()
{
	return $this->CHI_NGUOI_NHAN;
}	        
public function setCHI_NOI_DUNG($CHI_NOI_DUNG) 
{
	$this->CHI_NOI_DUNG = $CHI_NOI_DUNG;
}
public function getCHI_NOI_DUNG()
{
	return $this->CHI_NOI_DUNG;
}	        
public function setCHI_SO_TIEN($CHI_SO_TIEN) 
{
	$this->CHI_SO_TIEN = $CHI_SO_TIEN;
}
public function getCHI_SO_TIEN()
{
	return $this->CHI_SO_TIEN;
}	        
public function setCHI_DIA_CHI($CHI_DIA_CHI) 
{
	$this->CHI_DIA_CHI = $CHI_DIA_CHI;
}
public function getCHI_DIA_CHI()
{
	return $this->CHI_DIA_CHI;
}	        
public function setCHI_PHAN_LOAI($CHI_PHAN_LOAI) 
{
	$this->CHI_PHAN_LOAI = $CHI_PHAN_LOAI;
}
public function getCHI_PHAN_LOAI()
{
	return $this->CHI_PHAN_LOAI;
}	        
public function setCHI_NGAY_CHI($CHI_NGAY_CHI) 
{
	$this->CHI_NGAY_CHI = $CHI_NGAY_CHI;
}
public function getCHI_NGAY_CHI()
{
	return $this->CHI_NGAY_CHI;
}	        
public function setIS_ACTIVE($IS_ACTIVE) 
{
	$this->IS_ACTIVE = $IS_ACTIVE;
}
public function getIS_ACTIVE()
{
	return $this->IS_ACTIVE;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `chi`(                        
			`CHI_ID`, 
				`CHI_SO_PHIEU`, 
				`CHI_NGUOI_NHAN`, 
				`CHI_NOI_DUNG`, 
				`CHI_SO_TIEN`, 
				`CHI_DIA_CHI`, 
				`CHI_PHAN_LOAI`, 
				`CHI_NGAY_CHI`, 
				`IS_ACTIVE` 
		)
	VALUES(
    		:CHI_ID, 
	    		:CHI_SO_PHIEU, 
	    		:CHI_NGUOI_NHAN, 
	    		:CHI_NOI_DUNG, 
	    		:CHI_SO_TIEN, 
	    		:CHI_DIA_CHI, 
	    		:CHI_PHAN_LOAI, 
	    		:CHI_NGAY_CHI, 
	    		:IS_ACTIVE 
	    );";
	$parameters = array(
			":CHI_ID", 
				":CHI_SO_PHIEU", 
				":CHI_NGUOI_NHAN", 
				":CHI_NOI_DUNG", 
				":CHI_SO_TIEN", 
				":CHI_DIA_CHI", 
				":CHI_PHAN_LOAI", 
				":CHI_NGAY_CHI", 
				":IS_ACTIVE" 
		);
    $values = array(  
    		$this->getCHI_ID(), 
	    		$this->getCHI_SO_PHIEU(), 
	    		$this->getCHI_NGUOI_NHAN(), 
	    		$this->getCHI_NOI_DUNG(), 
	    		$this->getCHI_SO_TIEN(), 
	    		$this->getCHI_DIA_CHI(), 
	    		$this->getCHI_PHAN_LOAI(), 
	    		$this->getCHI_NGAY_CHI(), 
	    		$this->getIS_ACTIVE() 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setCHI_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "delete from `chi`
	                where `CHI_ID` = :CHI_ID;";
	        $parameters = array(":CHI_ID");
	        $values = array($this->getCHI_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `chi` SET 
			`CHI_ID`=:CHI_ID,
				`CHI_SO_PHIEU`=:CHI_SO_PHIEU,
				`CHI_NGUOI_NHAN`=:CHI_NGUOI_NHAN,
				`CHI_NOI_DUNG`=:CHI_NOI_DUNG,
				`CHI_SO_TIEN`=:CHI_SO_TIEN,
				`CHI_DIA_CHI`=:CHI_DIA_CHI,
				`CHI_PHAN_LOAI`=:CHI_PHAN_LOAI,
				`CHI_NGAY_CHI`=:CHI_NGAY_CHI,
				`IS_ACTIVE`=:IS_ACTIVE
			WHERE `CHI_ID` = :CHI_ID;";
	            $parameters = array(
			":CHI_ID",
				":CHI_SO_PHIEU",
				":CHI_NGUOI_NHAN",
				":CHI_NOI_DUNG",
				":CHI_SO_TIEN",
				":CHI_DIA_CHI",
				":CHI_PHAN_LOAI",
				":CHI_NGAY_CHI",
				":IS_ACTIVE"
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getCHI_ID(),
				$this->getCHI_SO_PHIEU(),
				$this->getCHI_NGUOI_NHAN(),
				$this->getCHI_NOI_DUNG(),
				$this->getCHI_SO_TIEN(),
				$this->getCHI_DIA_CHI(),
				$this->getCHI_PHAN_LOAI(),
				$this->getCHI_NGAY_CHI(),
				$this->getIS_ACTIVE()
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`CHI_ID`,
				`CHI_SO_PHIEU`,
				`CHI_NGUOI_NHAN`,
				`CHI_NOI_DUNG`,
				`CHI_SO_TIEN`,
				`CHI_DIA_CHI`,
				`CHI_PHAN_LOAI`,
				`CHI_NGAY_CHI`,
				`IS_ACTIVE`
			FROM `chi` WHERE `CHI_ID` = :CHI_ID and `is_active`=1;";
	$parameters = array(":CHI_ID");
	$values = array($this->getCHI_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setCHI_ID($row->CHI_ID);
		$this->setCHI_SO_PHIEU($row->CHI_SO_PHIEU);
		$this->setCHI_NGUOI_NHAN($row->CHI_NGUOI_NHAN);
		$this->setCHI_NOI_DUNG($row->CHI_NOI_DUNG);
		$this->setCHI_SO_TIEN($row->CHI_SO_TIEN);
		$this->setCHI_DIA_CHI($row->CHI_DIA_CHI);
		$this->setCHI_PHAN_LOAI($row->CHI_PHAN_LOAI);
		$this->setCHI_NGAY_CHI($row->CHI_NGAY_CHI);
		$this->setIS_ACTIVE($row->IS_ACTIVE);
	}
	return $this;
		}
	}
	
        
        
        public function getChiByPhanLoai($phanloai,$db = null) {
	if ($db != null) {
	$sql = "SELECT
			`CHI_ID`,
				`CHI_SO_PHIEU`,
				`CHI_NGUOI_NHAN`,
				`CHI_NOI_DUNG`,
				`CHI_SO_TIEN`,
				`CHI_DIA_CHI`,
				`CHI_PHAN_LOAI`,
				`CHI_NGAY_CHI`,
				`IS_ACTIVE`
			FROM `chi` WHERE `CHI_PHAN_LOAI` = :CHI_PHAN_LOAI and `is_active`=1;";
	$parameters = array(":CHI_PHAN_LOAI");
	$values = array($phanloai);
	$types = array(PDO::PARAM_STR);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	 if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new chi();
    	 $obj->setCHI_ID($row->CHI_ID);
		 $obj->setCHI_SO_PHIEU($row->CHI_SO_PHIEU);
		 $obj->setCHI_NGUOI_NHAN($row->CHI_NGUOI_NHAN);
		 $obj->setCHI_NOI_DUNG($row->CHI_NOI_DUNG);
		 $obj->setCHI_SO_TIEN($row->CHI_SO_TIEN);
		 $obj->setCHI_DIA_CHI($row->CHI_DIA_CHI);
		 $obj->setCHI_PHAN_LOAI($row->CHI_PHAN_LOAI);
		 $obj->setCHI_NGAY_CHI($row->CHI_NGAY_CHI);
		 $obj->setIS_ACTIVE($row->IS_ACTIVE);
		$objects[] = $obj;
    }
    return $objects;
    }
	
		}
	}
        
        
        
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`CHI_ID`,
				`CHI_SO_PHIEU`,
				`CHI_NGUOI_NHAN`,
				`CHI_NOI_DUNG`,
				`CHI_SO_TIEN`,
				`CHI_DIA_CHI`,
				`CHI_PHAN_LOAI`,
				`CHI_NGAY_CHI`,
				`IS_ACTIVE`
			FROM `chi` WHERE `is_active`=1 ORDER BY XUAT_ID DESC;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new chi();
    	 $obj->setCHI_ID($row->CHI_ID);
		 $obj->setCHI_SO_PHIEU($row->CHI_SO_PHIEU);
		 $obj->setCHI_NGUOI_NHAN($row->CHI_NGUOI_NHAN);
		 $obj->setCHI_NOI_DUNG($row->CHI_NOI_DUNG);
		 $obj->setCHI_SO_TIEN($row->CHI_SO_TIEN);
		 $obj->setCHI_DIA_CHI($row->CHI_DIA_CHI);
		 $obj->setCHI_PHAN_LOAI($row->CHI_PHAN_LOAI);
		 $obj->setCHI_NGAY_CHI($row->CHI_NGAY_CHI);
		 $obj->setIS_ACTIVE($row->IS_ACTIVE);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

